var courseHTML="";
var graphicHTML="";
var lessonData=[];
/*获取收藏课程*/
function getCourse(){
    ym.ajax({
        url: "/usercollectid/course",
        param:{
            /* userId:'1'*/
        },
        success: function (data) {
            var newData=data.obj;
            lessonData=newData;
            if(newData.length!==0){
            	for (var i = 0; i < newData.length; i++) {
                    courseHTML+="<div class='content-tab dynamic-tab' articleId='"+newData[i].coursePackageId+"'>"+
                        "<div class='cart-title'>"+
                        "<p class='cart-id'>收藏于"+newData[i].createTime+"</p>"+
                        "</div>"+
                        "<div class='dynamic-tab-desc'>"+
                        "<ul class='am-list cart-list'>"+
                        '<li class="am-g am-list-item-desced am-list-item-thumbed am-list-item-thumb-left" onclick="javascript:window.location.href=\'packagedetails.html?coursePackageId='+newData[i].coursePackageId+'\'">'+
                        "<div>"+
                        "<div class='am-u-sm-3 am-list-thumb fmImg'>"+
                        "<a href='javascript:void(0)'>"+
                        "<img src='"+newData[i].attachment_url+"' />"+
                        "</a>"+
                        "</div>"+
                        "<div class=' am-u-sm-8 am-list-main w72'>"+
                        "<h3 class='am-list-item-hd twospace'><a href='javascript:void(0)'>"+newData[i].course_package_name+"</a></h3>"+
                        "</div>"+
                        "</div>"+
                        "</li>"+
                        "</ul>"+
                        "</div>"+
                        "</div>"+
                        "</div>"+
                        "</li>"+
                        "</ul>"+
                        "</div>"+
                        "</div>";
                       
                }
                $('.lesson').html(courseHTML);
            }else{
                courseHTML = '<li class="am-text-center backw"><img style="width:35%;" src="../img/no.jpg"></li>';
                $('.lesson').html(courseHTML);
            }
        }
    });
}
/*获取收藏文章*/
function getGraphic(){
    ym.ajax({
        url: "/usercollectid/graphic",
        param:{
            /* userId:'1'*/
        },
        success: function (data) {
            var newData=data.obj;
            if(newData.length!==0){
                for (var i = 0; i < newData.length; i++) {
                    graphicHTML+="<div class='content-tab dynamic-tab' articleId='"+newData[i].articleId+"'>"+
                        "<div class='cart-title'>"+
                        "<p class='cart-id'>收藏于"+newData[i].createTime+"</p>"+
                        "</div>"+
                        "<div class='dynamic-tab-desc'>"+
                        "<ul class='am-list cart-list'>"+
                        "<li class='am-g am-list-item-desced am-list-item-thumbed am-list-item-thumb-left'>"+
                        "<div>"+
                        "<div class='am-u-sm-3 am-list-thumb fmImg'>"+
                        "<a href='javascript:void(0)'>"+
                        "<img src='"+newData[i].attachmentUrl+"' />"+
                        "</a>"+
                        "</div>"+
                        "<div class=' am-u-sm-8 am-list-main w72'>"+
                        "<h3 class='am-list-item-hd twospace'><a href='javascript:void(0)'>"+newData[i].articleTitle+"</a></h3>"+
                        "</div>"+
                        "</div>"+
                        "</li>"+
                        "</ul>"+
                        "</div>"+
                        "</div>"+
                        "</div>"+
                        "</li>"+
                        "</ul>"+
                        "</div>"+
                        "</div>";
                }
                $('.all-order').html(graphicHTML);
            }else{
               graphicHTML = '<li class="am-text-center backw"><img style="width:35%;" src="../img/no.jpg"></li>';
                $('.all-order').html(graphicHTML);
            }
            getCourse();
        }
    });
}
$(function(){
	getGraphic();
    /*查看文章详情*/
    $('body').on('click','.all-order .content-tab',function(){
        var articleId=$(this).attr('articleId');
        console.log(articleId)
        console.log()
        ym.ajax({
            url:'/article/updateArticleReadNumber',
            type:'post',
            param:{ articleId:articleId},
            success:function(data){
                if(data.res ==1){
                    console.log("数据获取成功跳转页面！")
                }else{console.log("数据获取失败！")}
                window.location.href='yimiaoxinwenXq.html?articleId='+articleId;
            }
        });
    })
/*查看课程详情*/
/*$('body').on('click','.lesson .content-tab',function(){
    var lessonId=$(this).attr('lessonId');
    console.log(lessonId)
    for (var i = 0; i < lessonData.length; i++) {
        if(lessonData[i].coursePackageId==lessonId){
        	window.location.href="./packagedetails.html?coursePackageId="+lessonData[i].coursePackageId+
                                                      "&jieshu="+lessonData[i].SectionNumber+
                                                      "&jiage="+lessonData[i].total_price+
                                                      "&goumaics="+lessonData[i].total_price+
                                                      "&zjr="+lessonData[i].lecturer+
                                                      "&title="+lessonData[i].course_package_name+"\"";
        }
    }
    })*/

})
